package space.goldchen.kafka.kafka;

/**
 * kafka接口，调用生产者发送消息
 * @author 2021
 * @create 2025-04-16 16:28
 */

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaController {

    @Resource
    private KafkaProducer kafkaProducer;

    /**
     * 使用KafkaProducer发送消息
     * @param message
     * @return
     */
    @GetMapping("/send")
    public String sendMessage(@RequestParam String message) {
        kafkaProducer.sendMessage("my-topic", message);
        return "Message sent: " + message;
    }
}
